
//
// 101214 - AH - (Hector) Created.
// 101219 - AH - (Garage *) Fixed so roots with no children also get tree
//               icon.
// 110606 - AH - (Garage) Changes related to that tree now has SoekratName.
// 110610 - AH - (Bybanen *) Now extends DefaultTreeCellRenderer so can be
//               passed to DefaultTreeCellEditor constructor.
//

package org.soekrat.gui.swing.forest;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;

import org.soekrat.engine.SoekratName;
import org.soekrat.engine.forest.Forest;
import org.soekrat.engine.forest.Tree;

/**
 * <p>
 *   {@link TreeCellRenderer} used for rendering
 *   {@link Tree}s in a
 *   {@link Forest}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
@SuppressWarnings("serial")
public final class SoekratTreeCellRenderer extends DefaultTreeCellRenderer 
{
  /**
   * <p>
   *   Shared single instance.
   * </p>
   */
  public final static DefaultTreeCellRenderer INSTANCE=
    new SoekratTreeCellRenderer();
  
  //private final ImageIcon m_icon;
  
  //private final DefaultTreeCellRenderer m_dtcrR=new DefaultTreeCellRenderer();
  
  //private final DefaultTreeCellRenderer m_dtcr=new DefaultTreeCellRenderer();
  
  // Singleton constructor.
  private SoekratTreeCellRenderer()
  {
    //URL iconUrl=getClass().getResource(
    //  "/org/soekrat/gui/swing/icons/miniTree2.png");
    //m_icon=new ImageIcon(iconUrl);
    
    //m_dtcrR.setLeafIcon(m_icon);
    //m_dtcrR.setClosedIcon(m_icon);
    //m_dtcrR.setOpenIcon(m_icon);
  }

  @Override
  public Component getTreeCellRendererComponent(JTree tree, Object value,
    boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
  {
    if (value instanceof Tree)
    {
      Tree node=(Tree)value;
    
      SoekratName sname=node.getSoekratName();
      String name=sname.toString();
      
      return super.getTreeCellRendererComponent(tree, name, selected, 
        expanded, leaf, row, hasFocus);
    
      /*
      if (node.isRoot())
      {
        //System.out.println(" -- icon 4 : "+name);
        return m_dtcrR.getTreeCellRendererComponent(tree, name, selected, 
          expanded, leaf, row, hasFocus);
      }
      else
      {
        //System.out.println(" -- NON icon 4 : "+name);
        return m_dtcr.getTreeCellRendererComponent(tree, name, selected, 
          expanded, leaf, row, hasFocus);
      }
      */
    }
    else
    {
      //System.out.println(" -- NOT TREE : "+value+" is : "+value.getClass().getName());
      return super.getTreeCellRendererComponent(tree, value, selected, 
        expanded, leaf, row, hasFocus);
    }
  }
  
}
